import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
export default defineConfig(({ mode }) => {
	const env = loadEnv(mode, process.cwd())
	const { VITE_API_URL, VITE_API_BASE_URL } = env

	return {
		plugins: [vue()],
		resolve: {
			alias: {
				'@': path.resolve(__dirname, './src'), // 路径别名
			},
			extensions: ['.js', '.ts', '.json'], // 导入时想要省略的扩展名列表
		},
		server: {
			host: '0.0.0.0',
			port: 3100,
			open: false,
			cors: true,
			proxy: {
				[VITE_API_BASE_URL]: {
					target: VITE_API_URL,
					changeOrigin: true,
					rewrite: (path) => path.replace(new RegExp(VITE_API_BASE_URL), ''), // 不可以省略rewrite
				},
			},
		},
	}
})
